home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-SPAR.{_A / SOFTIRQ.H < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-17  |  2.6 KB  |  132 lines

  1. /* softirq.h: 64-bit Sparc soft IRQ support.
  2.  *
  3.  * Copyright (C) 1997, 1998 David S. Miller (davem@caip.rutgers.edu)
  4.  */
  5.  
  6. #ifndef __SPARC64_SOFTIRQ_H
  7. #define __SPARC64_SOFTIRQ_H
  8.  
  9. #include <asm/atomic.h>
  10. #include <asm/hardirq.h>
  11. #include <asm/system.h>        /* for membar() */
  12.  
  13. #ifndef __SMP__
  14. extern unsigned int local_bh_count;
  15. #else
  16. #define local_bh_count        (cpu_data[smp_processor_id()].bh_count)
  17. #endif
  18.  
  19. /* The locking mechanism for base handlers, to prevent re-entrancy,
  20.  * is entirely private to an implementation, it should not be
  21.  * referenced at all outside of this file.
  22.  */
  23.  
  24. #define get_active_bhs()    (bh_mask & bh_active)
  25. #define clear_active_bhs(mask)            \
  26.     __asm__ __volatile__(            \
  27. "1:    ldx    [%1], %%g7\n"            \
  28. "    andn    %%g7, %0, %%g5\n"        \
  29. "    casx    [%1], %%g7, %%g5\n"        \
  30. "    cmp    %%g7, %%g5\n"            \
  31. "    bne,pn    %%xcc, 1b\n"            \
  32. "     nop"                    \
  33.     : /* no outputs */            \
  34.     : "HIr" (mask), "r" (&bh_active)    \
  35.     : "g5", "g7", "cc", "memory")
  36.  
  37. extern inline void init_bh(int nr, void (*routine)(void))
  38. {
  39.     bh_base[nr] = routine;
  40.     atomic_set(&bh_mask_count[nr], 0);
  41.     bh_mask |= 1 << nr;
  42. }
  43.  
  44. extern inline void remove_bh(int nr)
  45. {
  46.     bh_mask &= ~(1 << nr);
  47.     membar("#StoreStore");
  48.     bh_base[nr] = NULL;
  49. }
  50.  
  51. extern inline void mark_bh(int nr)
  52. {
  53.     set_bit(nr, &bh_active);
  54. }
  55.  
  56. #ifndef __SMP__
  57.  
  58. extern inline void start_bh_atomic(void)
  59. {
  60.     local_bh_count++;
  61.     barrier();
  62. }
  63.  
  64. extern inline void end_bh_atomic(void)
  65. {
  66.     barrier();
  67.     local_bh_count--;
  68. }
  69.  
  70. /* These are for the irq's testing the lock */
  71. #define softirq_trylock(cpu)    (local_bh_count ? 0 : (local_bh_count=1))
  72. #define softirq_endlock(cpu)    (local_bh_count = 0)
  73. #define synchronize_bh()    barrier()
  74.  
  75. #else /* (__SMP__) */
  76.  
  77. extern atomic_t global_bh_lock;
  78. extern spinlock_t global_bh_count;
  79.  
  80. extern void synchronize_bh(void);
  81.  
  82. static inline void start_bh_atomic(void)
  83. {
  84.     atomic_inc(&global_bh_lock);
  85.     synchronize_bh();
  86. }
  87.  
  88. static inline void end_bh_atomic(void)
  89. {
  90.     atomic_dec(&global_bh_lock);
  91. }
  92.  
  93. /* These are for the IRQs testing the lock */
  94. static inline int softirq_trylock(int cpu)
  95. {
  96.     if (spin_trylock(&global_bh_count)) {
  97.         if (atomic_read(&global_bh_lock) == 0) {
  98.             ++(cpu_data[cpu].bh_count);
  99.             return 1;
  100.         }
  101.         spin_unlock(&global_bh_count);
  102.     }
  103.     return 0;
  104. }
  105.  
  106. static inline void softirq_endlock(int cpu)
  107. {
  108.     (cpu_data[cpu].bh_count)--;
  109.     spin_unlock(&global_bh_count);
  110. }
  111.  
  112. #endif /* (__SMP__) */
  113.  
  114. /*
  115.  * These use a mask count to correctly handle
  116.  * nested disable/enable calls
  117.  */
  118. extern inline void disable_bh(int nr)
  119. {
  120.     bh_mask &= ~(1 << nr);
  121.     atomic_inc(&bh_mask_count[nr]);
  122.     synchronize_bh();
  123. }
  124.  
  125. extern inline void enable_bh(int nr)
  126. {
  127.     if (atomic_dec_and_test(&bh_mask_count[nr]))
  128.         bh_mask |= 1 << nr;
  129. }
  130.  
  131. #endif /* !(__SPARC64_SOFTIRQ_H) */
  132.